<?php

namespace V1;
class Send extends \ResourceClass
{
    public $isActive = true;
    public $remark = '订单发货';
    public $sendType;
    public $shipInfo;

    public function __construct()
    {
        $this->sendType = array(
            'JH_01' => 1, //自己联系物流
            'JH_02' => 2, //在线下单
            'JH_03' => 3, //无需物流
            'JH_04' => 4, //自定义物流
            'JH_05' => 5, //家装发货
            'JH_99' => 6  //国际物流
        );
        $this->shipInfo = array(
            'SendType' => '',              //订单发货类别
            'LogisticName' => '',          //订单发货类别
            'LogisticType' => '',          //快递类别【JH前缀为国内快递 ，JHI为国际快递】
            'PlatOrderNo' => '',           //平台订单号
            'LogisticNo' => '',            //快递运单号
            'IsSplit' => 0,               //是否拆单发货【是否拆单发货】
            'SubPlatOrderNo' => '',        //平台子订单交易单号
            'SenderName' => '',            //发货人姓名
            'SenderTel' => '',             //发货人联系电话
            'SenderAddress' => '',         //发货人地址
            'IsHwgFlag' => 0,             //是否为海外购【是=1；否=0】
        );
    }

    /*
     * 订单发货
     */
    public function post(array $post)
    {
        $data = array();
        $orderSn = isset($post['PlatOrderNo']) ? $post['PlatOrderNo'] : '';

        if (!isset($post['LogisticName'])) {
            printError('缺少参数：LogisticName', "40001");
        }
        if (!isset($post['LogisticType'])) {
            printError('缺少参数：LogisticType', "40001");
        }
        if (!isset($post['LogisticNo'])) {
            printError('缺少参数：LogisticNo', "40001");
        }
        if (!isset($post['PlatOrderNo'])) {
            printError('缺少参数：PlatOrderNo', "40001");
        }
        try{
            \Util\LogUtil::log('request_send_log',json_encode($post));
            $plat_order_no = isset($post['PlatOrderNo']) ? $post['PlatOrderNo'] : ''; //平台订单号
            $logistic_number = $post['LogisticNo']; //快递运单号
            $logistic_name = $post['LogisticName']; // 快递名称
            $is_split = $post['IsSplit']; // 是否拆单发货(拆单=1 ，不拆单=0)
            $sub_plat_order_no= $post['SubPlatOrderNo']; // 子订单号
            if( $plat_order_no[0] == 'Z'){ // 直购订单
                $shop_order_biz = new \Biz\ShopOrder();
                $shop_order_biz->sendLogistics($plat_order_no,$logistic_number,$logistic_name,$is_split,$sub_plat_order_no);
            }else{  // 提货订单
                $pick_up_biz = new \Biz\PickUp();
                $pick_up_biz->sendLogistics($plat_order_no,$logistic_number,$logistic_name,$is_split,$sub_plat_order_no);
            }
        }catch (\Exception $e){
            printError($e->getMessage(), "40001");
        }


        $data['code'] = '10000';
        $data['message'] = 'SUCCESS';
        return $data;
    }

}